<?php

// 20090211
// first implementation				
		
		if ($_REQUEST['profile_name']) {
			$profile_name = mb_strtolower($_REQUEST['profile_name'],"UTF-8");
			$query        = "SELECT id from users where name='" . $profile_name ."'";
			$result = mysql_query($query);
			if (mysql_num_rows($result)){ 
				$profile_id = mysql_result ($result,0);
			}
		} 
		elseif ($_REQUEST['profile_id']){
			$profile_id   = mb_strtolower($_REQUEST['profile_id']  ,"UTF-8");
			$query        = "SELECT name from users where id='" . $profile_id ."'";
			$result = mysql_query($query);
			if (mysql_num_rows($result)){ 
				$profile_name = mysql_result ($result,0);
			}
		}
		elseif ($id) {
			$profile_id   = $id;
			$profile_name = $user;
		} 

//---- begin public photos
		
		$query      = "SELECT * from photos where `owner`='$profile_id' and `access`=0";
		$result 		=	 mysql_query($query);
		if (mysql_num_rows($result)) {
			while ($photoinfo = mysql_fetch_assoc($result)){
			$photos =      "<div class=\"photothumb\"><a href=\"/index.php?do=viewphoto&photo_id=".$photoinfo['id']."\">
											<img border=\"0\" src=\"index.php?do=getphoto&square=1&size=100&id=".$photoinfo['id']."\" title=\"".
											$photoinfo['title']."\"></a></div>$photos";
			unset($photoinfo);
			}
		$SITE_MIDDLE .= FormatElement ( GetLangString ( $lang, "txt_publicphotoalbum" ) ,  GetLangString ( $lang, "msg_publicphotoalbum" ) . "<br>$photos"); 
		unset($photos);		
		} else {
			$SITE_MIDDLE .= FormatElement ( GetLangString ( $lang, "txt_publicphotoalbum" ) ,  GetLangString ( $lang, "msg_publicphotoalbumempty" ));
		} 
		

//---- begin friend photos
	$query        = "SELECT * from friends where user1='$id' and user2='$profile_id'";
	$result = mysql_query($query);
	if (mysql_num_rows($result)   or $profile_id==$id){ 
		$query2        = "SELECT * from friends where user2='$id' and user1='$profile_id'";
		$result2 = mysql_query($query2);
		if (mysql_num_rows($result2)  or $profile_id==$id){ 
		//is friend
			$query3      = "SELECT * from photos where `owner`='$profile_id' and `access`=1";
			$result3 		=	 mysql_query($query3);
			if (mysql_num_rows($result3)) {
				while ($photoinfo = mysql_fetch_assoc($result3)){
				$photos =      "<div class=\"photothumb\"><a href=\"/index.php?do=viewphoto&photo_id=".$photoinfo['id']."\">
										<img border=\"0\" src=\"index.php?do=getphoto&square=1&size=100&id=".$photoinfo['id']."\" title=\"".
										$photoinfo['title']."\"></a></div>$photos";
				unset($photoinfo);
				}
				$SITE_MIDDLE .= FormatElement ( GetLangString ( $lang, "txt_friendphotoalbum" ) ,  GetLangString ( $lang, "msg_friendphotoalbum" ) . "<br>$photos");
			} else {
				$SITE_MIDDLE .= FormatElement ( GetLangString ( $lang, "txt_friendphotoalbum" ) ,  GetLangString ( $lang, "msg_friendphotoalbumempty" ));
			}
		} else {
				$SITE_MIDDLE .= FormatElement ( GetLangString ( $lang, "txt_friendphotoalbum" ) ,  GetLangString ( $lang, "msg_friendphotoalbumdenied" ));
		}
	}
unset ($photos);
// /* ---- begin private photos 

	$query        = "SELECT * from privatephotos where user='$id'";
	$result = mysql_query($query);
	if (mysql_num_rows($result)){ 
		while ($private = mysql_fetch_array($result)){
			$photoid = $private['photo'];
			$query2      = "SELECT * from photos where `id`='$photoid'";
			$result2 		=	 mysql_query($query2);
			$photoinfo = mysql_fetch_array($result2);	
			$photos =      "<div class=\"photothumb\"><a href=\"/index.php?do=viewphoto&photo_id=".$photoinfo['id']."\">
									<img border=\"0\" src=\"index.php?do=getphoto&square=1&size=100&id=".$photoinfo['id']."\" title=\"".
									$photoinfo['title']."\"></a></div>$photos";
		}
		$SITE_MIDDLE .= FormatElement ( GetLangString ( $lang, "txt_privatephotoalbum" ) ,  GetLangString ( $lang, "msg_privatephotoalbum" ) . "<br>$photos");
	} else {
		$SITE_MIDDLE .= FormatElement ( GetLangString ( $lang, "txt_privatephotoalbum" ) ,  GetLangString ( $lang, "msg_privatephotoalbumempty" ));
	}
	




?>
